#include "odbc/types.hpp"
#include <boost/type_traits/is_same.hpp>
#include <boost/test/auto_unit_test.hpp>

namespace
{

	using namespace odbc;

#define BUILT_IN_TYPE_TEST_EX( T, TN, VALUE) \
	BOOST_AUTO_TEST_CASE( BOOST_JOIN( test_type_traits_for, TN)) \
	{ \
		typedef type_traits< T> TT; \
		TT::value_type val = VALUE; \
		TT::buffer_type buffer; \
		BOOST_CHECK( (boost::is_same< T, TT::value_type>::value)); \
		BOOST_CHECK( (boost::is_same< T, TT::buffer_type>::value)); \
		BOOST_CHECK_EQUAL( val, TT::convert( val) ); \
		\
		TT::convert( val, buffer); \
		BOOST_CHECK_EQUAL( val, buffer); \
		BOOST_CHECK_EQUAL( static_cast<void*>(&buffer), TT::buffer_to_void( const_cast< TT::buffer_type&>( buffer))); \
		BOOST_CHECK_EQUAL( static_cast<void*>(&buffer), TT::buffer_to_void( const_cast< const TT::buffer_type&>( buffer))); \
		BOOST_CHECK_EQUAL( sizeof( T), TT::size_of_buffer( buffer)); \
		BOOST_CHECK_EQUAL( sizeof( T), TT::size_of_value( val)); \
		BOOST_CHECK_EQUAL( T(0), TT::create_buffer()); \
		BOOST_CHECK_NO_THROW( TT::destroy_buffer( buffer)); \
	}

#define BUILT_IN_TYPE_TEST( TYPE, VALUE) \
	BUILT_IN_TYPE_TEST_EX( TYPE, TYPE, VALUE)

BUILT_IN_TYPE_TEST( char, 'A')
BUILT_IN_TYPE_TEST_EX( unsigned char, unsigned_char, 'A')
BUILT_IN_TYPE_TEST( wchar_t, L'A')
BUILT_IN_TYPE_TEST( short, -10)
BUILT_IN_TYPE_TEST_EX( unsigned short, unsigned_short, 10)
BUILT_IN_TYPE_TEST( int, -100000)
BUILT_IN_TYPE_TEST_EX( unsigned int, unsigned_int, 100000)
BUILT_IN_TYPE_TEST( long, -100000)
BUILT_IN_TYPE_TEST_EX( unsigned long, unsigned_long, 100000)
BUILT_IN_TYPE_TEST( float, -10000.302)
BUILT_IN_TYPE_TEST( double, -100000.09)

// TODO: Test gregorian date, posix time, std::string and std::wstring

} // namespace 
